import Mock from 'mockjs'
// mock的配置
Mock.setup({
    //随机延时500-1000毫秒
    timeout: '500-1000'
})
//拦截接口
//匹配路径规则
//请求方式
//返回数据
// Mock.mock(/\/my\/test/, test , () => {
//     //随机数据逻辑，目标：5条数据[{id: '', name: ''}]
//     const arr = []
//     for(let i = 0; i < 5;i++) {
//         arr.push(Mock.mock({
//             id: '@id',
//             name: '@cname',
//             image: '@image(250x250)'
//         }))
//     }
//     return {msg: '获取数据成功', result: arr}
// })


// 个人中心，我的收藏模拟接口
import qs from 'qs'
Mock.mock(/\/member\/collect/, 'get', config => {
    const queryString = config.url.split('?')[1]
    const queryObject = qs.parse(queryString)
    const items = []
    for (let i = 0; i < +queryObject.pageSize; i++) {
      items.push(Mock.mock({
        id: '@id',
        name: '@ctitle(10,20)',
        desc: '@ctitle(4,10)',
        price: '@float(100,200,2,2)',
        // http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_7.jpg
        picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock('@integer(1,8)')}.jpg`
      }))
    }
    return {
      msg: '获取收藏商品成功',
      result: {
        counts: 35,
        pageSize: +queryObject.pageSize,
        page: +queryObject.page,
        items
      }
    }
  })

